package com.ytzl.itrip.controller;

import com.ytzl.itrip.common.DtoUtil;
import com.ytzl.itrip.dto.Dto;
import com.ytzl.itrip.pojo.ItripImage;
import com.ytzl.itrip.vo.ItripImageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by sam on 2018/2/10.
 */
@Controller
@Api(tags = "酒店房间模块业务")
@RequestMapping("/api/hotel")
public class HotelRoomController extends BaseController {


    @ApiOperation(value = "根据targetId查询酒店房型图片(type=1)", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "根据酒店房型ID查询酒店房型图片" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码：</p>" +
            "<p>100301 : 获取酒店房型图片失败 </p>" +
            "<p>100302 : 酒店房型id不能为空</p>")
    @RequestMapping(value = "/getimg/{targetId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto<Object> getImgByTargetId(@ApiParam(required = true, name = "targetId", value = "酒店房型ID") @PathVariable String targetId) {
        Dto<Object> dto = null;
        if (null != targetId && !"".equals(targetId)) {
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("type", "1");
            param.put("targetId", targetId);
            try {
                List<ItripImageVO> itripImageList = itripImageService.getItripImageListByMap(param);
                return DtoUtil.returnSuccess("获取酒店图片房型成功", itripImageList);
            } catch (Exception e) {
                e.printStackTrace();
                return DtoUtil.returnFail("获取酒店房型图片失败", "100301");
            }
        } else {
            return DtoUtil.returnFail("酒店房型id不能为空", "100302");
        }
    }
}
